﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ecdl.demo.model.expression;

using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml.Packaging;

using System.Xml.Serialization;
using System.Xml;

namespace ecdl.demo.model.expression {
    public class FooterSelector : Selector{

        public FooterSelector() {
            AddSelector(new TypedSelector<WordprocessingDocument, OpenXmlElement>(GetAllFooters));
            AddSelector(new TypedSelector<MainDocumentPart, OpenXmlElement>(GetFootersFromMainDocumentPart));
        }

        private IEnumerable<OpenXmlElement> GetAllFooters(WordprocessingDocument document) {
            return GetFootersFromMainDocumentPart(document.MainDocumentPart);
        }

        private IEnumerable<OpenXmlElement> GetFootersFromMainDocumentPart(MainDocumentPart part) {
            var footers = new List<OpenXmlElement>();
            foreach (var footerPart in part.FooterParts) {
                footers.Add(footerPart.RootElement);
            }
            return footers;
        }
    }

    public class FooterSelectorDTO : SingleExpressionDTO{

        public FooterSelectorDTO() : base(typeof(FooterSelector)){
        }
    }
}
